import time
from pprint import pprint
import requests
from googletrans import Translator
translator = Translator()
import asyncio 

github_token ="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"

headers = {
    "Authorization": f"token {github_token}",
    "Accept": "application/vnd.github.v3+json",
}

params = {
    "sort": "created",
    "direction": "asc",
    "per_page": 50,
    "page": 1,
}



async def unstar_repo():
    url = "https://api.github.com/user/starred"
    response = requests.get(url, headers=headers , params=params)
    if response.status_code == 200:
        data = response.json()
        for repo in data:
            repo_name = repo['full_name']
            desc = repo['description'];
            desc = await translator.translate(desc , src='en', dest='zh-cn')
            desc = desc.text
            url = f"https://api.github.com/user/starred/{repo_name}"
            response = requests.delete(url, headers=headers)

            if response.status_code == 204:
                print(f"Unstarred {repo_name}")
                print(f"Desc {desc}\n ")
                
            else:
                print(f"Failed to unstar {repo_name}")
        return data

    else:
        print("Failed to get starred repos")


if __name__ == '__main__':
     asyncio.run(unstar_repo())
   

